import React, { PureComponent } from 'react';
import Touch from './touch';

export default class SortCeil extends PureComponent {
    static defaultProps = {
        onChange: () => {},
        data: {},
        enable: true,
    };

    componentDidMount() {
        if (this.props.enable) {
            this.touch = new Touch(this.$dom, this.props.data);
            this.touch.on('change', this.props.onChange).on('click', this.props.onClick);
            this.$dom.touch = this.touch;
        }
    }

    render() {
        const { className = '', enable, ...otherProps } = this.props;
        if (enable) {
            delete otherProps.onClick;
        }
        return (
            <div
                className={`sort-ceil ${className}`}
                {...otherProps}
                ref={d => {
                    this.$dom = d;
                }}
            >
                {this.props.children}
            </div>
        );
    }
}
